using System;
using System.Collections.Generic;

using SBPweb.Forge.Contracts.Components;

namespace SBPweb.Forge.Contracts.Logging
{
	/// <summary>
	/// Class of LogManagerBase
	/// </summary>
    public abstract class LogManagerBase : InitializableBase, ILogManager
    {

        #region Constructor logic

		/// <summary>
		/// Constructor of LogManagerBase
		/// </summary>
        public LogManagerBase()
        {
		}

        #endregion

        #region Public properties

		/// <summary>
		/// Collection of Categories
		/// </summary>
        public abstract ICollection<string> Categories
        {
            get;
        }

        #endregion

        #region Public event handlers

		/// <summary>
		/// Event for write
		/// </summary>
        public event EventHandler<LogWriteEventArgs> Written;

        #endregion

        #region Public methods

		/// <summary>
		/// Write critical to log
		/// </summary>
		/// <param name="sender">sender</param>
		/// <param name="obj">object</param>
		/// <param name="category">category</param>
		public virtual void WriteCritical(object sender, object obj, string category)
        {
            OnWrite(sender, SeverityLevel.Critical, obj, category);
        }

		/// <summary>
		/// Write error to log
		/// </summary>
		/// <param name="sender">sender</param>
		/// <param name="obj">object</param>
		/// <param name="category">category</param>
        public virtual void WriteError(object sender, object obj, string category)
        {
            OnWrite(sender, SeverityLevel.Error, obj, category);
        }

		/// <summary>
		/// Write info to log
		/// </summary>
		/// <param name="sender">sender</param>
		/// <param name="obj">object</param>
		/// <param name="category">category</param>
		public virtual void WriteInfo(object sender, object obj, string category)
        {
            OnWrite(sender, SeverityLevel.Information, obj, category);
        }

		/// <summary>
		/// Write something to log
		/// </summary>
		/// <param name="sender">sender</param>
		/// <param name="obj">object</param>
		/// <param name="category">category</param>
		public virtual void Write(object sender, object obj, string category)
        {
            OnWrite(sender, SeverityLevel.None, obj, category);
        }

        /// <summary>
        /// Write something to log
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="obj">object</param>
        /// <param name="category">category</param>
        /// <param name="title">title</param>
        /// <param name="priority">priority</param>
        /// <param name="eventId">eventId</param>
        public virtual void Write(object sender, object obj, string category, string title, int priority, int eventId)
        {
            OnWrite(sender, SeverityLevel.None, obj, category, title, priority, eventId);
        }

		/// <summary>
		/// Write verbose to log
		/// </summary>
		/// <param name="sender">sender</param>
		/// <param name="obj">object</param>
		/// <param name="category">category</param>
		public virtual void WriteVerbose(object sender, object obj, string category)
        {
            OnWrite(sender, SeverityLevel.Verbose, obj, category);
        }

		/// <summary>
		/// Write warning to log
		/// </summary>
		/// <param name="sender">sender</param>
		/// <param name="obj">object</param>
		/// <param name="category">category</param>
		public virtual void WriteWarning(object sender, object obj, string category)
        {
            OnWrite(sender, SeverityLevel.Warning, obj, category);
        }

        #endregion

        #region Private helpers

        /// <summary>
        /// Write message to log
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="severity">severity</param>
        /// <param name="obj">object</param>
        /// <param name="category">category</param>
        protected virtual void OnWrite(object sender, SeverityLevel severity, object obj, string category)
        {
            if (Written != null)
            {
                Written.Invoke(sender, new LogWriteEventArgs(severity, obj, category));
            }
        }

        /// <summary>
        /// Write message to log
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="severity">severity</param>
        /// <param name="obj">object</param>
        /// <param name="category">category</param>
        /// <param name="title">title</param>
        /// <param name="priority">priority</param>
        /// <param name="eventId">eventId</param>
        protected virtual void OnWrite(object sender, SeverityLevel severity, object obj, string category, string title, int priority, int eventId)
        {
            if (Written != null)
            {
                Written.Invoke(sender, new LogWriteEventArgs(severity, obj, category, priority, title, eventId));
            }
        }

        #endregion

	}
}